/**
 * 944. 删列造序
 * https://leetcode.cn/problems/delete-columns-to-make-sorted/
 */

/**
 * @param {string[]} strs
 * @return {number}
 */
function minDeletionSize(strs) {
  const flags = new Array(strs[0].length);
  let count = 0;
  for (let i = 1; i < strs.length; i += 1) {
    const pre = strs[i - 1];
    const cur = strs[i];
    for (let j = 0; j < cur.length; j += 1) {
      if (!flags[j]) {
        if (cur[j] < pre[j]) {
          flags[j] = true;
          count += 1;
        }
      }
    }
  }
  return count;
}

console.log(minDeletionSize(['abc', 'bce', 'cae']) === 1);
console.log(minDeletionSize(['cba', 'daf', 'ghi']) === 1);
console.log(minDeletionSize(['a', 'b']) === 0);
console.log(minDeletionSize(['zyx', 'wvu', 'tsr']) === 3);
